package com.example.ch05_05;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;

public class MainActivity extends Activity {
	
	private Button button1;
	private Button button2;
	//private LinearLayout panel1;
	private ViewGroup panel;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		initView();
		initHandler();
	}

	private void initHandler() {
		// TODO Auto-generated method stub
		button1.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				panel.setVisibility(View.VISIBLE);
				button1.setVisibility(View.INVISIBLE);
				button2.setVisibility(View.VISIBLE);
				Animation appear = AnimationUtils.loadAnimation(MainActivity.this,R.anim.anim_appear);
				panel.setAnimation(appear);
			}
		});
button2.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				panel.setVisibility(View.INVISIBLE);
				button2.setVisibility(View.INVISIBLE);
				button1.setVisibility(View.VISIBLE);
				Animation disappear = AnimationUtils.loadAnimation(MainActivity.this,R.anim.anim_disappear);
				panel.setAnimation(disappear);
			}
		});
	}

	private void initView() {
		// TODO Auto-generated method stub
		button1 = (Button) this.findViewById(R.id.button1);
		button2 = (Button) this.findViewById(R.id.button2);
		panel = (ViewGroup)this.findViewById(R.id.panel1);
		panel.setVisibility(View.INVISIBLE);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}
